package com.zhdl.network.common_server;

import cn.hutool.core.util.HexUtil;
import com.project.command.faq.analysis.ComAnalysis;
import com.project.command.faq.analysis.ComAnalysisData;
import com.project.command.faq.analysis.ComAnalysisResult;
import com.project.common.constant.Dic;
import com.zhdl.network.common_server.dto.ServerTcpDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 手操器ModbusTcp响应数据,解析
 */
@Slf4j
@Service(Dic.HAND_MODBUS_RTU_ANALYSIS)
public class CommonTcpServerAnalysisImpl implements ComAnalysis<ServerTcpDto, List<ServerTcpDto>> {

    @Override
    public ComAnalysisResult<ServerTcpDto> analysisData(ComAnalysisData<List<ServerTcpDto>> data) {
        return new ComAnalysisResult<>(data.getBuf());
//        List<ModbusDto> modbusFrames = data.getBuf();
//        if (modbusFrames.size() > 0) {
//            log.debug("拼出完整数据包个数:" + modbusFrames.size());
//        }
//        return new ComAnalysisResult<>(modbusFrames);
    }

    @Override
    public String getHeadAnalysis() {
        return "";
    }

    @Override
    public byte[] getAfterAnalysis(String cmdStr) {
        return HexUtil.decodeHex(cmdStr);
    }
}
